package com.example.design.c.state.demo2;

import lombok.Getter;
import lombok.Setter;

/**
 * 学生分数抽象状态
 */
@Setter
@Getter
public abstract class AbstractScoreState {

    /**
     * 上下文对象
     */
    private ScoreContext context;

    /**
     * 总分
     */
    private int totalScore;

    /**
     * 分数状态名称
     */
    private String stateName;

    /**
     * 抽象处理逻辑
     */
    protected abstract void checkState();

    /**
     * 累加分数
     *
     * @param score 分数值
     */
    protected void addScore(int score) {
        int totalScore = this.getTotalScore();
        totalScore += score;
        this.setTotalScore(totalScore);
        checkState();
    }
}
